home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16288 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  54 lines

  1. Path: fang.dsto.defence.gov.au!usenet
  2. From: IainJameson <Iain.Jameson@dsto.defence.gov.au>
  3. Newsgroups: comp.lang.c++
  4. Subject: Opening, closing then opening files.
  5. Date: Wed, 10 Apr 1996 12:38:03 +0930
  6. Organization: DSTO,Australia
  7. Message-ID: <316B2613.1A5@dsto.defence.gov.au>
  8. NNTP-Posting-Host: fang.dsto.defence.gov.au
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.01 (X11; I; HP-UX A.09.01 9000/735)
  13.  
  14. Hi 
  15.  
  16. I have a small problem.
  17.  
  18. I have the following C++ code :
  19.  
  20. ifstream inFile;
  21. char *file_name;
  22.  
  23. void do_stuff(...)
  24. {
  25. ...
  26. ...
  27.  
  28. inFile.open(file_name,ios::in);
  29.  
  30. ...
  31. ...
  32. }
  33.  
  34. I open file_name, read the contents and do stuff.
  35. Then I want to open a different file_name
  36. using this same piece of code. Unfortunately I can't.
  37.  
  38. I know that I should change inFile to be a pointer to ifstream and use
  39. delete and new, but 
  40.  
  41. 1 : I want to change as little code as possible, and
  42. 2 : I did this and got an `illegal instruction' error when I tried to
  43. run
  44.     run the programme. I have no idea why.
  45.  
  46. So the question is, how do I keep the original code and open a different
  47. file_name? Can it be done without changing the original code too much?
  48. Or do I have to make inFile a pointer to ifstream? If I do, how do I get
  49. rid of the illegal instruction error?
  50.  
  51. Suggestions would be appreciated.
  52.  
  53. Iain Jameson.
  54.